﻿<cfscript>
/** 
* ORM BookPublisher
* 
* @hint "Hibernate persistenter t_publisher. 教材出版社" 
* 
*/ 

component 
	displayname="public.service.orm.senate.BookPublisher" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="BookPublisher" 
	table="t_publisher"
	{

	property type="string" name="PubID" column="pid" fieldtype="id" generator="assigned" hint="出版社编号";

	property type="string" name="Publisher" column="publisher" hint="出版社名称";
	property type="numeric" name="BookCount" column="book_count" hint="教材数量";

	property type="string" name="PinYin" column="pyidx" hint="拼音首字母缩写检索";
	property type="string" name="FirstLetter" column="pyid" hint="拼音首字母";

	property name="Books" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="pid" cfc="Book" hint="出版的教材";
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getNextID() output=false {
		
		var nextID = numberFormat(1, "0___");
		var checkArray = ORMExecuteQuery("select PubID from BookPublisher 
											order by PubID desc", {}, { maxResults=1 });
		
		/* 
			主键生成规则 CHAR(4)
			
			4位为流水号 出版社自动编码
			
		*/
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0___");
			
		}

		return nextID;
	}

}

</cfscript>